package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.PurchaseCourseRecords;
import com.whw.fy.service.PurchaseCourseRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Api(tags = "购买课程记录模块")
@RestController
@RequestMapping("/api/purchaseCourseRecords")
public class PurchaseCourseRecordsController {
    @Resource
    private PurchaseCourseRecordsService purchaseCourseRecordsService;

    @ApiOperation(value = "新增购买课程记录")
    @PostMapping("/")
    public Message insert(PurchaseCourseRecords p){
        p.setPostTime(new Date());
        return purchaseCourseRecordsService.insertSelective(p);
    }

    @ApiOperation(value = "根据id删除购买课程记录")
    @DeleteMapping("/")
    public Message delete(int id){
        return purchaseCourseRecordsService.deleteByPrimaryKey(id);
    }

    @ApiOperation(value = "根据id修改购买课程记录")
    @PutMapping("/")
    public Message update(PurchaseCourseRecords p){
        return purchaseCourseRecordsService.updateByPrimaryKeySelective(p);
    }

    @ApiOperation(value = "根据id查看购买课程记录")
    @GetMapping("/one")
    public Message selectById(int id){
        return purchaseCourseRecordsService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "获取所有该买记录")
    @GetMapping("/all")
    public Message selectAll(){
        return purchaseCourseRecordsService.selectAll();
    }

    @ApiOperation(value = "根据studentId获得购买课程记录")
    @GetMapping("/stuId")
    public Message selectByStudentId(int studentId){
        return purchaseCourseRecordsService.selectByStudentId(studentId);
    }

    @ApiOperation(value = "根据studentId和status获得购买课程记录")
    @GetMapping("/stuIdAndStatus")
    public Message selectByStudentIdAndClassStatus(Integer studentId, Integer classStatus){
        return purchaseCourseRecordsService.selectByStudentIdAndClassStatus(studentId, classStatus);
    }

}
